﻿using OA.Core;
using OA.Core.Helper;
using OA.Model.MyAttribute;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OA.Model
{
    public enum ApprovalType
    {
        [Description("待审核")]
        Zero = 0,

        [Description("需沟通")]
        One = 1,

        [Description("会签")]
        Two = 2,

        [Description("同意")]
        Three = 3,

        [Description("不同意")]
        Four = 4,

        [Description("已撤回")]
        Five = 5,

        [Description("回退")]
        Six = 6,

        [Description("转移")]
        Seven = 7,

    }

    

    [Table("Approval")]
    public class Approval : BaseInfo
    {
        /// <summary>
        /// -1 被删除 0 待发起  1 已发起 2:撤回 3 审核不通过 4 已审核
        /// </summary>
        [Display(Name = "状态")]
        [Description("-1 被删除 0 待发起  1 已发起 2:撤回 3 审核不通过 4 已审核")]
        public int Status { get; set; }

        [NotMapped]
        public string StatusName { get {
                switch (this.Status){

                    case -1:return "被删除";
                    case 0: return "待发起";
                    case 1: return "已发起";
                    case 2: return "已撤回";
                    case 3: return "审核不通过";
                    case 4: return "已审核";
                    default:return this.Status.ToString();
                }
            } 
        }

        public int CustomID { get; set; }

        public int FormID { get; set; }        

        [MaxLength(50)]
        public string Title { get; set; }

        public string No { get; set; }        

        

        public string SponsorEmpID { get; set; }

        public int SponsorPositionID { get; set; }

        /// <summary>
        /// 解释说明
        /// </summary>
        [MaxLength(200)]
        public string Explain { get; set; }

        /// <summary>
        /// 当前审批人
        /// </summary>
        [MaxLength(50)]
        public string Suspense { get; set; }

        public string SuspenseEmpID { get; set; }

        public DateTime? FinishTime { get; set; }

        [MaxLength(200)]
        public string NeedExplainEmpID { get; set; }

        /// <summary>
        /// 同步状态
        /// </summary>
        public int Synchronization { get; set; }

        /// <summary>
        /// 同步结果
        /// </summary>
        public string Result { get; set; }

        


        public virtual ICollection<ApprovalItem> ApprovalItem { get; set; }

    }

    public class SimpleApproval
    {
        public int CustomID { get; set; }

        public int FormID { get; set; }
        public string No { get; set; }

        public string Title { get; set; }

        public int Status { get; set; }
        public bool Selected { get; set; } = false;

    }

    [Table("ApprovalItem")]
    public class ApprovalItem : BaseInfo
    {
        

        public int ApprovalID { get; set; }
      

        /// <summary>
        /// 当前审批节点ID
        /// </summary>
        public int ApprovalNodeID { get; set; }

        /// <summary>
        /// 审批时间
        /// </summary>
        public DateTime? ApprovalTime { get; set; }

        /// <summary>
        /// 0：待审核 1：需沟通  2：会签  3:同意  4:不同意 5:已撤回 6:回退
        /// </summary>
        public int Status { get; set; }

        [NotMapped]
        public string StatusName { get { return MyEnum.GetEnumNameByValue(this.Status, typeof(ApprovalType)); } }


        /// <summary>
        /// 意见
        /// </summary>
        [MaxLength(200)]
        [Tag(TagEnum.Text, "required", "意见", 2, 200)]
        public string Explain { get; set; }

        /// <summary>
        /// 提交的数据
        /// </summary>
        public string Data { get; set; }

        /// <summary>
        /// 当前步骤
        /// </summary>
        public int Step { get; set; }

        /// <summary>
        /// 节点类型 1:普通类型 2:会签类型
        /// </summary>
        public int PointType { get; set; }

        /// <summary>
        /// 审批人
        /// </summary>
        [MaxLength(10)]
        public string EmpID { get; set; }

        [MaxLength(20)]
        public string EmpName { get; set; }

        public int PositionID { get; set; }

       
        public string PositionName { get; set; }

        public int DepartmentID { get; set; }

        
        public string DepartmentName { get; set; }


        /// <summary>
        /// 实际处理人
        /// </summary>
        [MaxLength(10)]
        public string RealEmpID { get; set; }

        [MaxLength(20)]
        public string RealEmpName { get; set; }


        public int RealPositionID { get; set; }


        public string RealPositionName { get; set; }

        public int RealDepartmentID { get; set; }


        public string RealDepartmentName { get; set; }

       
        [MaxLength(200)]
        public string IP { get; set; }

        /// <summary>
        /// 1:PC 2:小程序
        /// </summary>
        public int OS { get; set; }

        public virtual Approval Approval { get; set; }

        /// <summary>
        /// 审批人头像
        /// </summary>
        public string Pic { get; set; }         

        public bool IsPush { get; set; }

    }
}
